import { eventHandler, getRouterParam } from 'h3';
import { verifyAccessToken } from '~/utils/jwt-utils';
import {
  sleep,
  unAuthorizedResponse,
  useResponseSuccess,
  useResponseError,
} from '~/utils/response';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return unAuthorizedResponse(event);
  }

  await sleep(600);

  const id = getRouterParam(event, 'id');

  // 模拟检查车辆状态
  // 这里模拟一些车辆处于不可删除状态
  const undeletableIds = [1, 2, 3]; // 模拟出车中或维保中的车辆ID

  if (undeletableIds.includes(Number(id))) {
    return useResponseError('当前车辆处于出车中或维保中状态，无法删除');
  }

  return useResponseSuccess(null);
});
